﻿using RemoteManger.Entity;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RemoteManger.Remote
{
    public partial class AddLink : Form
    {
        SqlSugarScopeProvider db;
        long groupId = 0;
        Action RefushData;
        public AddLink(long _groupId,Action Refrush)
        {
            InitializeComponent();
            Load += AddLink_Load;
            this.groupId = _groupId;
            db = SqlHelper.GetInstance();
            this.RefushData = Refrush;
        }

        private void AddLink_Load(object? sender, EventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MachineInfo machineInfo = new MachineInfo();
            machineInfo.GroupId = groupId;
            machineInfo.Title = txtName.Text;
            machineInfo.Ip = txtip.Text;
            machineInfo.Port = txtPort.Text.ToInt();
            machineInfo.UserName = txtAccount.Text;
            machineInfo.Password = txtPwd.Text;
            machineInfo.Remark = txtRemark.Text;
            bool result = db.Insertable(machineInfo).ExecuteCommand() > 0;
            if (result)
            {
                MessageBox.Show("添加成功");
                this.RefushData();

                this.Close();
            }
            else
            {
                MessageBox.Show("添加失败");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
